package com.web.base.wechat.dao;

import com.blue.jdbc.BaseDao;
import com.web.base.wechat.model.WechatTemplate;
import org.springframework.stereotype.Repository;

@Repository("wechatTemplateDao")
public class WechatTemplateDao extends BaseDao<WechatTemplate>
{
	public WechatTemplateDao()
	{
	}

	@Override
	protected void query(StringBuilder sql, WechatTemplate param)
	{
		if (param != null)
		{
			if (param.getWechatId() != null && param.getWechatId() > 0)
				sql.append(" and a.wechat_id=:wechatId");

			if (param.getState() != null)
				sql.append(" and a.state=:state");

			if (param.getCode() != null && !param.getCode().isEmpty())
				sql.append(" and a.code=:code");

		}
		sql.append(" order by a.id");
	}

	@Override
	protected StringBuilder select()
	{
		StringBuilder sql = new StringBuilder(64);
		sql.append("select a.*, w.name wechat_name from wx_wechat_template a");
		sql.append(" left join wx_wechat w on w.id=a.wechat_id");
		sql.append(" where 1=1");
		return sql;
	}

}
